package com.avic.rong.search.adapter.homePageAdapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager.LayoutParams;
import com.avic.rong.R;
import com.avic.rong.bean.product.GoodBean;
import com.avic.rong.utils.DensityUtils;
import com.avic.rong.utils.GlideUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Creater: Created by wangyz on 2019/9/18.
 * Email: 936804097@qq.com
 */
public class VCultivateAdapter extends DelegateAdapter.Adapter<VCultivateAdapter.VCultivateViewHolder> {


    private Context mContext;
    private LayoutHelper mLayoutHelper;
    private LayoutParams mLayoutParams;
    private List<GoodBean> beanList = new ArrayList<>();

    public void setBeanList(List<GoodBean> beanList) {
        this.beanList = beanList;
    }

    public VCultivateAdapter(Context context, LayoutHelper layoutHelper, List<GoodBean> beanList) {
        this(context, layoutHelper, beanList, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    }

    public VCultivateAdapter(Context context, LayoutHelper layoutHelper, List<GoodBean> beanList, @NonNull LayoutParams layoutParams) {
        this.mContext = context;
        this.mLayoutHelper = layoutHelper;
        this.beanList = beanList;
        this.mLayoutParams = layoutParams;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }

    @NonNull
    @Override
    public VCultivateViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {

        return new VCultivateViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_course_index, parent, false));
    }

    @Override
    public int getItemCount() {
        return beanList.size();
    }

    @Override
    public void onBindViewHolder(@NonNull VCultivateViewHolder cultivateViewHolder, int positon) {
        GoodBean bean = beanList.get(positon);


        cultivateViewHolder.tv_course_name.setText(bean.getTitle());


        GlideUtils.loaderHanldeRoundImage(mContext, bean.getImg(), cultivateViewHolder.img_course_logo, R.mipmap.online_default, DensityUtils.dp2px(mContext, 6));


//        standardItemViewHolder.itemView.setOnClickListener(new MyClickListener(standardItemViewHolder, bean));
        //添加购物车
//        standardItemViewHolder.img_shop_car.setOnClickListener(new MyClickListener(standardItemViewHolder, bean));


    }


    public class VCultivateViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.img_course_logo)
        ImageView img_course_logo;
        @BindView(R.id.tv_course_name)
        TextView tv_course_name;
        @BindView(R.id.tv_course_total_time)
        TextView tv_course_total_time;
        @BindView(R.id.tv_course_time)
        TextView tv_course_time;
        @BindView(R.id.tv_course_price)
        TextView tv_course_price;
        @BindView(R.id.line)
        View line;


        public VCultivateViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        protected void finalize() throws Throwable {
            super.finalize();
        }
    }


}
